<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: categories_top.php 140 2013-09-22 07:44:23Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 140 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:44:23 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$box_smarty = new Smarty();

if (!CacheCheck() && !FORCE_CACHE) {
	$cache=false;
	$box_smarty->caching = false;
} else {
	$cache=true;
	$box_smarty->caching = true;
	$box_smarty->cache_lifetime = CACHE_LIFETIME;
	$box_smarty->cache_modified_check = CACHE_CHECK;
	$cache_id = 'box_categories_top'.$_SESSION['language'].'_'.$_SESSION['customers_status']['customers_status_id'].$cPath;
}

if(!$box_smarty->isCached(CURRENT_TEMPLATE.'/boxes/box_categories_top.html', $cache_id) || !$cache){
	require_once(DIR_FS_INC.'inc.count_products_in_category.php');
	
	$cat_config = array('min_level' =>	4,
						'max_level' =>	false,
						'hide_empty' =>	(CATEGORY_HIDE_EMPTY=='true'?true:false));

	function categories_top($catid = 0, $level = 1) {

		global $cPath, $current_category_id, $cat_config, $db;

		$myPathArray = explode('_',$cPath);

		if(GROUP_CHECK == 'true')
			$group_check = " AND c.group_permission_".$_SESSION['customers_status']['customers_status_id']." = 1 ";

		$categories = $db->db_query("SELECT
											c.categories_id,
											cd.categories_name
										FROM
											".TABLE_CATEGORIES." c
											LEFT JOIN ".TABLE_CATEGORIES_DESCRIPTION." AS cd
											ON (cd.categories_id = c.categories_id AND cd.language_id = ".(int)$_SESSION['languages_id'].")
										WHERE
											c.parent_id = ".(int)$catid."
										AND
											c.categories_status = 1
											".$group_check."
										ORDER BY
											sort_order", true);

		while(!$categories->EOF) {
			$open_ul = '';
			$current = false;
			$has_sub = false;
			
			if($categories->fields['categories_id'] == $current_category_id)
				$current = ' a_level_'.$level.'_current current';
				
			elseif(in_array($categories->fields['categories_id'], $myPathArray)) {
				$current = ' a_level_'.$level.'_current currentparent';
				$open_ul = 'current_ul';
			}
			
			if(SHOW_COUNTS == 'true' || $cat_config['hide_empty'] == true)
				$products = count_products_in_category($categories->fields['categories_id']);
			
			if(($products != 0 && $cat_config['hide_empty'] == true) || ($cat_config['hide_empty'] == false)) {
				if(categories_top($categories->fields['categories_id'],$level+1))
					$has_sub = true;
					
				$cat_tree 	.= 	"\n"
							.	'<li class="li_level_'.$level.(!empty($open_ul)?' '.$open_ul:'').'">'
							.	'<a title="'.$categories->fields['categories_name'].'" class="a_level_'.$level.' '.$current.($has_sub?' has_sub':'').'" href="'.href_link(FILENAME_DEFAULT, 'cPath='.$categories->fields['categories_id']).'">'
							.	$categories->fields['categories_name'];
				if($has_sub)
					$cat_tree .= '<span>&nbsp;</span>';
					
				if(SHOW_COUNTS == 'true')
					$cat_tree .=	' <em>('.$products.')</em>';
				
				$cat_tree 	.=	'</a>';
				if(($level < $cat_config['min_level'] || $current) && ($level < $cat_config['max_level'] || !$cat_config['max_level']))
					$cat_tree	.= 	categories_top($categories->fields['categories_id'], $level+1);
				
				$cat_tree 	.=	'</li>';
			}
			$categories->MoveNext();
		}

		if($cat_tree) {
			if($level == 1)
				$class .= ' class="navigation"';

			return 	'<ul'.$class.'>'.$cat_tree.'</ul>';
		}
	}
	$box_smarty->assign('language', $_SESSION['language']);
	$box_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
	$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');
	$box_smarty->assign('BOX_CONTENT', categories_top());
}
$get[] = 'ct=yes';
if(!$cache)
	$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_categories_top.html');
else
	$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_categories_top.html', $cache_id);